package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.data.ResultEnum;
import com.dongdongshop.pojo.TbItemCat;
import com.dongdongshop.service.ItemCatService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("itemCatController")
public class ItemCatContrroller {

    @DubboReference
    private ItemCatService itemCatService;

    @RequestMapping("getItemInfo")
    @ResponseBody
    public Result getItemInfo(Long parentId) {
        try {
            List<TbItemCat> itemInfo = itemCatService.getItemInfo(parentId);
            return Result.ok().setData(itemInfo);
        }catch (Exception e) {
            return Result.respones(ResultEnum.ERROR);
        }
    }

    @RequestMapping("getTypeId")
    @ResponseBody
    public Result getTypeId(Long id) {
        try {
            Long typeId = itemCatService.getTypeId(id);
            return Result.respones(ResultEnum.SUCCESS).setData(typeId);
        }catch (Exception e) {
            return Result.respones(ResultEnum.ERROR);
        }
    }
}
